const initState = {
  userInfo: {} as IUserInfo,
  // 4. 设置初始值
  // 5. 设置初始值类型
  profile: {} as IProfile,
};

type ActionType =
  | { type: "user/saveUserInfo"; payload: IUserInfo }
  // 6. 扩展ActionType
  | { type: "user/saveProfile"; payload: IProfile };

const userReducer = (
  state = initState,
  action: ActionType
): typeof initState => {
  switch (action.type) {
    case "user/saveUserInfo":
      return { ...state, userInfo: action.payload };
    // 8. 完成保存的reducer计算
    case "user/saveProfile":
      return { ...state, profile: action.payload };
    default:
      return state;
  }
};

export default userReducer;
